import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'

import { Routes, notFoundAndNoPower } from '@/router/routes'

import { userStore } from '@/store/modules/userStore'
export const router = createRouter({
  history: createWebHashHistory(),
  routes: [...notFoundAndNoPower, ...Routes],
})


// 路由加载前
router.beforeEach(async (to, from, next) => {
  console.log(to)
  if(to.meta.title){
    document.title = to.meta.title
  }
  const { token,LOGIN } = userStore()
  if(!token){
   LOGIN()
  }
  next()
})

// 路由加载后
router.afterEach(() => {
})

// 导出路由
export default router
